package cn.jiangjiesheng.bootstrap.commons.autorun;

import cn.jiangjiesheng.bootstrap.commons.interfaces.IPaasTableValidator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * Created by dev@jiangjiesheng.cn on 2021/11/18  <br/>
 *
 * @author dev@jiangjiesheng.cn
 */
@Component
@Slf4j
public class PaasTableValidatorAutoRun implements ApplicationRunner {

    @Nullable
    @Autowired
    private IPaasTableValidator paasTableValidator;

    /**
     * Callback used to run the bean.
     *
     * @param args incoming application arguments
     * @throws Exception on error
     */
    @Override
    public void run(ApplicationArguments args) throws Exception {
        if(Objects.nonNull(paasTableValidator)){
            paasTableValidator.verifyAndFastFailed();
        }
    }
}
